1735B - Tea with Tangerines - CodeForces Solution


greedy math

Please click on ads to support us..

Python Code:

t = int(input()) for item in range(t):
    orange_count = int(input())
    orange_list = input().split()
    orange_sizes = []
    for element in range(len(orange_list)):
        orange_sizes.append(int(orange_list[element]))
    base_slice = min(orange_sizes)*2-1
    count=0
    for orange in orange_sizes:
        count+=(orange-1)//base_slice     print(count)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fixed(x) cout << fixed << setprecision(x)
#define endl '\n'
void solved()
{
    ll n, c = 0;
    cin >> n;
    ll ar[n], y = 1e9;
    for (int i = 0; i < n; i++)
    {
        cin >> ar[i];
        y = min(y, ar[i]);
    }
    y = y * 2 - 1;
    for (int i = 0; i < n; i++)
    {
        if (ar[i] > y)
        {
            c = c + ar[i] / y;
            if (ar[i] % y == 0)
                c--;
        }
    }
    cout << c << endl; // 19 9
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t;
    cin >> t;
    while (t--)
        solved();
    return 0;
}


Comments

Submit
0 Comments
More Questions

513A - Game
1711E - XOR Triangle
688A - Opponents
20C - Dijkstra
1627D - Not Adding
893B - Beautiful Divisors
864B - Polycarp and Letters
1088A - Ehab and another construction problem
1177B - Digits Sequence (Hard Edition)
1155B - Game with Telephone Numbers
1284A - New Year and Naming
863B - Kayaking
1395B - Boboniu Plays Chess
1475D - Cleaning the Phone
617B - Chocolate
1051B - Relatively Prime Pairs
95B - Lucky Numbers
1692D - The Clock
1553D - Backspace
1670D - Very Suspicious
1141B - Maximal Continuous Rest
1341A - Nastya and Rice
1133A - Middle of the Contest
385A - Bear and Raspberry
1311B - WeirdSort
1713F - Lost Array
236B - Easy Number Challenge
275A - Lights Out
147A - Punctuation
253A - Boys and Girls